package com.mzmarket.market.module.mapper;

import com.mzmarket.market.module.entity.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ProductMapper {

    @Select("select * from product where id =#{id} and is_deleted = 0")
    Product getById(@Param("id") Long id);

    @Select("select * from product where id =#{id}")
    Product extractById(@Param("id") Long id);

    int insert(@Param("product") Product product);

    int update(@Param("product") Product product);

    @Update("update product set is_deleted = 1, update_time=#{time} where id = #{id} limit 1 ")
    int delete(@Param("id") Long id, @Param("time") Integer time);

    @Select("select * from product where is_deleted = 0")
    List<Product> getAll();

    Long count(@Param("keyword") String keyword);

    List<Product> getPageList(@Param("pageSize") Integer pageSize, @Param("offset") Long offset,
                              @Param("keyword") String keyword);

    @Select("select id from category where name like  CONCAT('%', #{keyword}, '%')")
    List<Long> getCategoryLikeId(@Param("keyword") String keyword);

    List<Product> getPageList2(@Param("pageSize") Integer pageSize, @Param("offset") Long offset,
                              @Param("keyword") String keyword,@Param("categoryLikeList") String categoryLikeList);
}
